//
//  LeftViewControlle.m
//  PetTown
//
//  Created by lanou3g on 15/5/29.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "LeftViewControlle.h"
#import "HomePageTableViewController.h"
#import "CollectionPageTableViewController.h"
#import "ObjectDescriptionViewController.h"
#import "DatabaseHandle.h"
#import "StoryTableViewController.h"
#import "SDImageCache.h"
@interface LeftViewControlle ()
@property (strong, readwrite, nonatomic) UITableView *tableView;
@end

@implementation LeftViewControlle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView = ({
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(20, (self.view.frame.size.height - 54 * 5) / 1.8f, self.view.frame.size.width, 54 * 6) style:UITableViewStylePlain];
        tableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.opaque = NO;
        tableView.backgroundColor = [UIColor clearColor];
        tableView.backgroundView = nil;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.bounces = NO;
        tableView;
    });
    [self.view addSubview:self.tableView];
    
    
}


#pragma mark -
#pragma mark UITableView Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
   
        case 0:
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[HomePageTableViewController alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;

        case 1:
           [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[ObjectDescriptionViewController alloc] init]]
                                            animated:YES];
                [self.sideMenuViewController hideMenuViewController];
                        break;
        case 2:
                [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[CollectionPageTableViewController alloc] init]] animated:YES];
            
                [self.sideMenuViewController hideMenuViewController];
                        break;
        case 3:{
            //清除缓存
            UIAlertController * alert1 = [UIAlertController alertControllerWithTitle:@"清除缓存" message:@"是否清除?" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction * c = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDefault handler:nil];
             UIAlertAction * d = [UIAlertAction actionWithTitle:@"确定" style: UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                 //清除缓存
                 SDImageCache * sdI = [SDImageCache sharedImageCache];
                 [sdI clearDisk];
                 [sdI clearMemory];
             }];
            
            [alert1 addAction:c];
            [alert1 addAction:d];
            [self presentViewController:alert1 animated:YES completion:nil];

            break;

            
        }
    
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    //清除缓存
    SDImageCache * sdI = [SDImageCache sharedImageCache];
    [sdI clearDisk];
    [sdI clearMemory];
}
#pragma mark -
#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 54;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString * cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.highlightedTextColor = [UIColor lightGrayColor];
        cell.selectedBackgroundView = [[UIView alloc] init];
    }
    
    NSArray * titles = @[@" 首页",@" 版权声明",@" 收藏",@" 清除缓存"];
    NSArray *images = @[@"shouye1.png",  @"banquanshengming.png", @"shoucang3.png", @"qingchuhuancun3.png"];
    cell.textLabel.text = titles[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];
    
    
    
    return cell;
}


//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
